<?php

namespace App\Repositories;

use App\Models\StationBills;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class ServiceBillRepository extends BaseRepository
{

    public function model()
    {
        return StationBills::class;
    }

    /**
     * @param $name
     * @param $created_at
     * @param $limit
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function getStationBills($name, $created_at, $limit)
    {
        $query = StationBills::query();
        if ($name !== false) {
            $query->where('service.designation', 'like', '%' . $name . '%');
        }
        if ($created_at !== false) {
            $query->where(DB::raw('month(station_bills.start_time)'), '=', date("m", strtotime($created_at)))
                ->where(DB::raw('year(station_bills.start_time)'), '=', date("Y", strtotime($created_at)));
        }/* else {
            $query->where(DB::raw('month(station_bills.start_time)'), '=', date("m", time()));
        }*/
        $stationBills = $query
            ->select(['station_bills.*', 'service.designation as service_name'])
            ->leftJoin('service', 'station_bills.service_id', '=', 'service.id')
            ->orderBy('station_bills.service_id')
            ->paginate($limit);
        return $stationBills;
    }

    protected function serialization(array $attributes)
    {
        // TODO: Implement serialization() method.
    }
}